package com.gxm.base.grammar_运算语法.stream;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

public class Demo {
    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        list.add(new Person("jack", 20));
        list.add(new Person("mike", 25));
        list.add(new Person("tom", 30));
        System.out.println(list.size());
        //保留年龄为 20 的 person 元素
        list = list.stream().filter(person -> person.getAge() == 20).collect(toList());
        System.out.println(list.get(0).getName());


        List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
        List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
        System.out.println(filtered.size());


        Random random = new Random();
        random.ints().limit(10).forEach(System.out::println);


        random.ints().limit(10).sorted().forEach(System.out::println);


    }
}
